import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
var _excluded = ["__id", "_status"];
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, encryptPwd } from 'utils/utils';
import intl from 'utils/intl';
var organizationId = getCurrentOrganizationId();
var tableDs = {
  selection: false,
  autoQuery: true,
  fields: [{
    name: 'syncTypeCode',
    type: 'string',
    required: true,
    lookupCode: 'CPFM.HR_SYNC_TYPE'
  }, {
    name: 'appId',
    type: 'string',
    required: true
  }, {
    name: 'authTypeMeaning',
    type: 'string',
    required: true
  }, {
    name: 'authAddress',
    type: 'string',
    required: true
  }, {
    name: 'enabledFlag',
    type: 'boolean',
    required: true,
    falseValue: 0,
    trueValue: 1,
    defaultValue: 1
  }],
  queryFields: [],
  transport: {
    read: function read() {
      return {
        url: "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/hr-syncs"),
        method: 'GET'
      };
    }
  }
};
var logDs = {
  selection: false,
  autoQuery: false,
  fields: [{
    name: 'lastUpdateDate',
    type: 'string',
    required: true
  }, {
    name: 'syncDirectionMeaning',
    type: 'string'
  }, {
    name: 'syncTypeMeaning',
    type: 'string',
    required: true
  }, {
    name: 'deptStatusMeaning',
    type: 'string',
    required: true
  }, {
    name: 'empStatusMeaning',
    type: 'string',
    required: true
  }],
  queryFields: [{
    name: 'startDate',
    type: 'dateTime',
    label: intl.get('cpfm.syncOuterSystem.model.sync.startDate').d('开始日期')
  }, {
    name: 'endDate',
    type: 'dateTime',
    label: intl.get('cpfm.syncOuterSystem.model.sync.endDate').d('结束日期')
  }],
  transport: {
    read: function read(_ref) {
      var dataSet = _ref.dataSet;
      var syncId = dataSet.syncId;
      return {
        url: "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/hr-syncs/").concat(syncId),
        method: 'GET'
      };
    }
  }
};
var tableDetailDs = {
  autoQueryAfterSubmit: false,
  fields: [{
    name: 'syncTypeCode',
    type: 'string',
    label: intl.get('cpfm.syncOuterSystem.model.sync.syncTypeCodeMeaning').d('同步类型'),
    required: true,
    lookupCode: 'CPFM.HR_SYNC_TYPE'
  }, {
    name: 'appId',
    type: 'string',
    label: intl.get('cpfm.syncOuterSystem.model.sync.appId').d('用户凭证'),
    required: true,
    maxLength: 200
  }, {
    name: 'appSecret',
    type: 'string',
    label: intl.get('cpfm.syncOuterSystem.model.sync.appSecret').d('用户密钥'),
    maxLength: 200
  }, {
    name: 'authType',
    type: 'string',
    label: intl.get('cpfm.syncOuterSystem.model.sync.authTypeMeaning').d('授权类型'),
    required: true,
    lookupCode: 'CPFM.HR_AUTH_TYPE'
  }, {
    name: 'authAddress',
    type: 'string',
    label: intl.get('cpfm.syncOuterSystem.model.sync.authAddress').d('三方授权地址'),
    maxLength: 240
  }, {
    name: 'enabledFlag',
    type: 'boolean',
    label: intl.get('cpfm.syncOuterSystem.model.wechatConfig.authType').d('启用'),
    required: true,
    defaultValue: 1,
    falseValue: 0,
    trueValue: 1
  }],
  transport: {
    read: function read(_ref2) {
      var dataSet = _ref2.dataSet;
      var syncId = dataSet.syncId;
      return {
        url: "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/hr-syncs/detail/").concat(syncId),
        method: 'GET',
        params: ''
      };
    },
    create: function create(_ref3) {
      var config = _ref3.config,
          data = _ref3.data,
          dataSet = _ref3.dataSet;

      var _data = _slicedToArray(data, 1),
          _data$ = _data[0],
          __id = _data$.__id,
          _status = _data$._status,
          rest = _objectWithoutProperties(_data$, _excluded);

      var publicKey = dataSet.queryParameter.publicKey;

      var newData = _objectSpread({}, rest);

      if (rest.appSecret) {
        newData.appSecret = encryptPwd(rest.appSecret, publicKey);
      }

      var url = "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/hr-syncs");
      return _objectSpread(_objectSpread({}, config), {}, {
        url: url,
        method: 'POST',
        data: _objectSpread(_objectSpread({}, newData), {}, {
          tenantId: organizationId
        })
      });
    },
    update: function update(_ref4) {
      var config = _ref4.config,
          data = _ref4.data,
          dataSet = _ref4.dataSet;
      var newData = Array.isArray(data) ? data[0] : {};
      var publicKey = dataSet.queryParameter.publicKey;

      if (newData.appSecret) {
        newData.appSecret = encryptPwd(newData.appSecret, publicKey);
      }

      var url = "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/hr-syncs");
      return _objectSpread(_objectSpread({}, config), {}, {
        url: url,
        method: 'PUT',
        data: newData
      });
    }
  }
};
var logDetailDs = {
  transport: {
    read: function read(_ref5) {
      var dataSet = _ref5.dataSet;
      var logId = dataSet.logId;
      return {
        url: "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/hr-syncs/logs/").concat(logId),
        method: 'GET'
      };
    }
  }
};
var handleUpdateDs = {
  transport: {
    read: function read(_ref6) {
      var dataSet = _ref6.dataSet;
      var requestData = dataSet.requestData;
      return {
        url: "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/hr-syncs/do"),
        method: 'POST',
        params: '',
        data: _objectSpread({}, requestData)
      };
    }
  }
};
var handleUpdateDsLocal = {
  transport: {
    read: function read(_ref7) {
      var dataSet = _ref7.dataSet;
      var requestData = dataSet.requestData;
      return {
        url: "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/hr-syncs/local"),
        method: 'POST',
        params: '',
        data: _objectSpread({}, requestData)
      };
    }
  }
};
export { tableDs, tableDetailDs, logDs, logDetailDs, handleUpdateDs, handleUpdateDsLocal };